﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Door: main.cpp Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                Examples using state machines generated by StateBuilderCpp
            </h1>
            <h3>
                Door: main.cpp Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">main.cpp</div>  </div>
</div>
<div class="contents">
<a href="main_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;cstdlib&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#pragma warning(push, 0)</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/*#ifdef _MSC_VER*/</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;boost/bind.hpp&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;boost/asio.hpp&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;logging.hpp&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#pragma warning(pop)</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/*#ifdef _MSC_VER*/</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="main_8h.html">main.h</a>&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="_door_8h.html">Door.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_door_tester_8h.html">DoorTester.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="keyword">using namespace </span>std;
<a name="l00021"></a>00021 <span class="keyword">namespace </span>bl = boost::logging;
<a name="l00022"></a>00022 
<a name="l00023"></a><a class="code" href="main_8cpp.html#a2c3f6775325c30275d11c6abee2db6a0">00023</a> <span class="keywordtype">int</span> <a class="code" href="main_8cpp.html#a2c3f6775325c30275d11c6abee2db6a0">main</a>(<span class="keywordtype">int</span> <span class="comment">/*argc*/</span>, <span class="keywordtype">char</span> ** <span class="comment">/*argv[]*/</span>)
<a name="l00024"></a>00024 {
<a name="l00025"></a>00025     <a class="code" href="class_app.html">App</a> app;
<a name="l00026"></a>00026     <span class="keywordflow">return</span> app.<a class="code" href="class_app.html#a2529b8f7291bf36fb2ecdbee4d6d335d">Main</a>();
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="class_app.html#acb8cbf3e285b91d0170ffe87df5989c5">00030</a> <a class="code" href="class_app.html#acb8cbf3e285b91d0170ffe87df5989c5">App::App</a>()
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032     logInit();
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="class_app.html#a2529b8f7291bf36fb2ecdbee4d6d335d">00035</a> <span class="keywordtype">int</span> <a class="code" href="class_app.html#a2529b8f7291bf36fb2ecdbee4d6d335d">App::Main</a>()
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037     BOOST_LOG_L3(<span class="stringliteral">&quot;Door Example&quot;</span>);
<a name="l00038"></a>00038 
<a name="l00039"></a>00039     <span class="keywordflow">try</span> {
<a name="l00040"></a>00040         boost::asio::io_service io_service;
<a name="l00041"></a>00041         BOOST_LOG_L3(<span class="stringliteral">&quot;Door constructor &quot;</span>);
<a name="l00042"></a>00042         <a class="code" href="class_door.html">Door</a> door(io_service);
<a name="l00043"></a>00043         BOOST_LOG_L3(<span class="stringliteral">&quot;DoorTester constructor &quot;</span>);
<a name="l00044"></a>00044         <a class="code" href="class_door_tester.html">DoorTester</a> doorTester(door, io_service);
<a name="l00045"></a>00045         BOOST_LOG_L3(<span class="stringliteral">&quot;Send the start event&quot;</span>);
<a name="l00046"></a>00046         doorTester.<a class="code" href="class_door_tester.html#acb66e5a64a0a6583d817bbb88c12c71c">EvStartTest</a>();
<a name="l00047"></a>00047         BOOST_LOG_L3(<span class="stringliteral">&quot;run the main loop&quot;</span>);
<a name="l00048"></a>00048         io_service.run();
<a name="l00049"></a>00049         BOOST_LOG_L3(<span class="stringliteral">&quot;End of run&quot;</span>);
<a name="l00050"></a>00050     }
<a name="l00051"></a>00051     <span class="keywordflow">catch</span> (std::exception&amp; e){
<a name="l00052"></a>00052         BOOST_LOG_L3(<span class="stringliteral">&quot;Exception: &quot;</span> &lt;&lt; e.what());
<a name="l00053"></a>00053         <span class="keywordflow">return</span> -1;
<a name="l00054"></a>00054     }
<a name="l00055"></a>00055     <span class="keywordflow">return</span> 0;
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="class_app.html#aee87822258073f2c99bca8e81dd212c2">00058</a> <span class="keywordtype">void</span> <a class="code" href="class_app.html#aee87822258073f2c99bca8e81dd212c2">App::logInit</a>()
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060   BOOST_LOG_INIT((<span class="stringliteral">&quot;&quot;</span> &gt;&gt; (*<span class="keyword">new</span> bl::time_element(<span class="stringliteral">&quot;%H:%M:%S%F&quot;</span>)) &gt;&gt; <span class="stringliteral">&quot;,&quot;</span>
<a name="l00061"></a>00061                      &gt;&gt; bl::mask &gt;&gt; <span class="stringliteral">&quot;,&quot;</span>
<a name="l00062"></a>00062                      &gt;&gt; (*<span class="keyword">new</span> bl::pretty_function_name_element()) &gt;&gt; <span class="stringliteral">&quot;:&quot;</span>
<a name="l00063"></a>00063                      &gt;&gt; bl::line &gt;&gt; <span class="stringliteral">&quot;:&quot;</span>
<a name="l00064"></a>00064                      &gt;&gt; bl::trace
<a name="l00065"></a>00065                      &gt;&gt; bl::eol)); <span class="comment">// log format</span>
<a name="l00066"></a>00066   
<a name="l00067"></a>00067   <span class="comment">//Standard output</span>
<a name="l00068"></a>00068   bl::sink sinkStdOutput(&amp;std::cout, BOOST_LOG_MASK_LEVEL_3);
<a name="l00069"></a>00069   sinkStdOutput.attach_qualifier(bl::log);
<a name="l00070"></a>00070   BOOST_LOG_ADD_OUTPUT_STREAM(sinkStdOutput);
<a name="l00071"></a>00071 
<a name="l00072"></a>00072   <span class="comment">//File</span>
<a name="l00073"></a>00073   bl::sink sinkFile(<span class="keyword">new</span> std::ofstream(<span class="stringliteral">&quot;./log.txt&quot;</span>), BOOST_LOG_MASK_LEVEL_4);
<a name="l00074"></a>00074   sinkFile.attach_qualifier(bl::log);
<a name="l00075"></a>00075   BOOST_LOG_ADD_OUTPUT_STREAM(sinkFile);
<a name="l00076"></a>00076 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
